/** 
* @file        zos_main.c
* @ingroup     zos_main
* @brief       主入口，用户在对应的接口中进行外设和私有应用任务的初始化，但不得长时间阻塞！
*/
/**
 * @defgroup zos main
 */
#include "zos.h"

//任务全局变量
zos_task_t user_main_task_Handle = NULL;

//获取信号强度
void Detection_csq(void)
{
	int i=20;
	zos_uint8_t rssi;
	do{
		if(nb_get_csq((int *)&rssi) == ZOS_EOK)
		{
			zos_printf("csq = %d\r\n",rssi);
			if(rssi<32)
			{
				break;
			}
		}
		zos_task_delay(5000);
	}while(i--);

	if(i<=1)
		nb_reboot();
}

//获取PDP 上下文激活状态
void Detection_CGACT(void)
{
	int i=20;
	zos_uint8_t cgact;

	do{
		if(nb_get_CGACT((int *)&cgact) == ZOS_EOK)
		{
			zos_printf("cgact=%d\r\n",cgact);
			if(cgact == 1)
			{
				break;
			}
		}
		zos_task_delay(5000);
	}while(i--);
	if(i<=1)
		nb_reboot();
}

//获取SIM卡 ICCID号码
void Detection_NCCID(void)
{
	int i=20;
	char nccid[25];

	memset(nccid, 0, sizeof(char)*25);
	do{
		if(nb_get_NCCID(nccid) == ZOS_EOK)
		{
			zos_printf("nccid=%s\r\n",nccid);
			break;
		}
		zos_task_delay(1000);
	}while(i--);
}

//获取当前网络时间
void Detection_Time(void)
{
	struct nb_time_t time;
	zos_task_delay(1000);
	if(zos_rtc_get_time(&time) == ZOS_EOK)
	{
		zos_printf("date:%d-%d-%d time:%d-%d-%d\r\n",time.tm_year,time.tm_mon,time.tm_mday,time.tm_hour,time.tm_min,time.tm_sec);
	}
	else
	{
		nb_reboot();
	}
}

void user_main_task()
{
	//Detection_NCCID();
	//Detection_csq();
	//Detection_CGACT();

	//Detection_Time();
	//osDelay(2000);

	//sensor_mpu6050_task();
	sensor_mpu6050_iic_task();
	//mqtt_tcp_emq_dashboard_init();

	user_main_task_Handle = ZOS_NULL;
	zos_task_exit();
}


int zos_main(void)
{
  	user_main_task_Handle = osThreadNew ((osThreadFunc_t)(user_main_task),NULL,"user_main_task",0x400,osPriorityNormal1);
	
	return 0;
}

#include "shell.h"

SHELL_EXPORT_CMD(Detection_csq,Detection_csq, cmd csq);
SHELL_EXPORT_CMD(Detection_Time,Detection_Time, cmd Time);
